import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_yn_goods/base/widget/base_list_more_get_builder.dart';
import 'package:flutter_yn_goods/config/app_color.dart';
import 'package:flutter_yn_goods/config/app_routes.dart';
import 'package:flutter_yn_goods/config/app_translations.dart';
import 'package:flutter_yn_goods/pages/completed_orders/completed_orders_logic.dart';
// import 'package:flutter_yn_goods/pages/completed_orders/model/model_completed_order.dart';
import 'package:flutter_yn_goods/pages/order/order_add/model/model_order_list.dart';
import 'package:flutter_yn_goods/utils/loading/loading_utils.dart';
import 'package:flutter_yn_goods/utils/utils_other.dart';
import 'package:flutter_yn_goods/widgets/appbar/common_app_bar.dart';
import 'package:flutter_yn_goods/widgets/image/image_view.dart';
import 'package:flutter_yn_goods/widgets/widget_line.dart';
import 'package:get/get.dart';

class CompletedOrdersPage extends StatelessWidget {
  final logic = Get.put(CompletedOrdersLogic(), tag: CompletedOrdersLogic.tag);

  CompletedOrdersPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return  BaseListMoreGetBuilder<CompletedOrdersLogic>(
      tag: CompletedOrdersLogic.tag,
      appBar: CommonAppBar(
        title: LocaleKeys.completed_orders.tr,
      ),
      enablePullDown: true,
      enablePullUp: true,
      initialRefresh: true,
      builder: (controller) {
        return ListView.builder(
          padding: EdgeInsets.all(16.w),
          itemCount: controller.list.length,
          itemBuilder: (context, index) {
            ModelOrderList item = controller.list[index] as ModelOrderList;
            return _buildOrderItem(item);
          },
        );
      },
    );
  }
  Widget _buildOrderItem(ModelOrderList order) {
    return Container(
      margin: EdgeInsets.only(bottom: 12.h),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.w),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            blurRadius: 6,
            offset: Offset(0, 2),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: EdgeInsets.all(12.w),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(
                  child: Row(
                    children: [
                      Text(
                        "${LocaleKeys.order_id.tr}: ",
                        style: TextStyle(
                          fontSize: 14.sp,
                          fontWeight: FontWeight.bold,
                          color: AppColor.color202020,
                        ),
                      ),
                      Expanded(
                        child: Text(
                          order.orderId ?? '',
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                            fontSize: 14.sp,
                            color: AppColor.color666666,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                GestureDetector(
                  onTap: () {
                    if (order.orderId != null && order.orderId!.isNotEmpty) {
                      Clipboard.setData(ClipboardData(text: order.orderId!));
                      LoadingUtils.showToast(LocaleKeys.copied_to_clipboard.tr);
                    }
                  },
                  child: Container(
                    padding: EdgeInsets.all(4.w),
                    child: Icon(
                      Icons.copy,
                      size: 18.w,
                      color: AppColor.color999999,
                    ),
                  ),
                ),
              ],
            ),
          ),

          const WidgetLine(),
          // 顾客信息部分
          Padding(
            padding: EdgeInsets.all(12.w),
            child: Row(
              children: [
                // 顾客头像
                ClipRRect(
                    borderRadius: BorderRadius.circular(20.w),
                    child:  ImageView(
                      imageUrl: order.phone,
                      width: 40.w,
                      height: 40.w,
                      fit: BoxFit.cover,
                    )


                ),
                SizedBox(width: 10.w),
                // 顾客信息
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        order.name ?? LocaleKeys.no_data.tr,
                        style: TextStyle(
                          fontSize: 14.sp,
                          fontWeight: FontWeight.bold,
                          color: AppColor.color202020,
                        ),
                      ),
                      SizedBox(height: 4.h),
                      Text(
                        order.phone ?? "",
                        style: TextStyle(
                          fontSize: 12.sp,
                          color: AppColor.color666666,
                        ),
                      ),
                      SizedBox(height: 4.h),
                      Text(
                        order.address ?? "",
                        style: TextStyle(
                          fontSize: 12.sp,
                          color: AppColor.color666666,
                        ),
                      ),
                    ],
                  ),
                ),
                // 订单状态
                // Container(
                //   padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.h),
                //   decoration: BoxDecoration(
                //     color: order.status == "1" ? AppColor.colorE1F4E7 : AppColor.colorFFEAEA,
                //     borderRadius: BorderRadius.circular(4.w),
                //   ),
                //   child: Text(
                //     order.status == "1" ? "已完成" : "待处理",
                //     style: TextStyle(
                //       fontSize: 12.sp,
                //       color: order.status == "1" ? AppColor.color21A95E : AppColor.primary,
                //     ),
                //   ),
                // ),
              ],
            ),
          ),

          const  WidgetLine(),

          // 商品信息部分
          Padding(
            padding: EdgeInsets.all(12.w),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                // 商品图片
                ClipRRect(
                  borderRadius: BorderRadius.circular(6.w),
                  child: ImageView(
                    imageUrl: order.image,
                    width: 80.w,
                    height: 80.w,
                    fit: BoxFit.cover,
                  ),
                ),
                SizedBox(width: 10.w),
                // 商品信息
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        order.storeName ?? "",
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                          fontSize: 13.sp,
                          color: AppColor.color202020,
                        ),
                      ),
                      SizedBox(height: 8.h),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            // ¥
                            UtilsOther.getGoodsPrice(order.totalPrice),
                            // "¥${(order.price ??'')}",
                            style: TextStyle(
                              fontSize: 15.sp,
                              fontWeight: FontWeight.bold,
                              color: AppColor.primary,
                            ),
                          ),

                        ],
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),


        ],
      ),
    );
  }




} 